<?php

namespace bc\model\knowledge;

use bc\ar\MActiveRecord;

class StatisticsModel extends MActiveRecord
{
	public $autoId = 'statistics_id';
	
	public static function tableName()
	{
		return '{{%knowledge_statistics}}';
	}
	
        public function getStatisticsList($params, $page = null, $pageSize = null)
        {
                $columns = self::getTableSchema()->name . '.*, bc_knowledge.title ';
		$ar = $this->find ()->select($columns)
				->leftJoin('bc_knowledge',  self::getTableSchema()->name . '.knowledge_id = bc_knowledge.id ')				
				->where($params);
		if ($page && $pageSize)
		{
			$offset = $this->getOffset ( $page, $pageSize );
			$ar->offset($offset)->limit($pageSize);
		}
	
		if($this->sort == null)
			$ar->orderBy ( $this->autoId . ' DESC' );
		else
			$ar->orderBy ( $this->sort );
		
		return $ar->asArray()->all();
        }
	
}

